package com.wbao.dianniu.ui;

import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import com.umeng.analytics.MobclickAgent;
import com.wbao.dianniu.logical.Const;
import com.wbao.dianniu.logical.GlobalContext;
import com.wbao.dianniu.utils.Notification;
import com.wbao.dianniu.R;
import com.wbao.dianniu.utils.Utils;

/**
 * 个性签名
 * 
 * @author yejianjun
 * 
 */
public class SignateEdit extends BaseActivity {

	private EditText mEditText;
	private Button rightBtn;
	private final int MAX_COUNT = 30;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentLayout(R.layout.signate_edit);
		setTitleName("编辑简介");
		mEditText = (EditText) findViewById(R.id.signateEdit);
		String result = getIntent().getStringExtra(Const.INTENT_SIGNATE);
		if (!TextUtils.isEmpty(result)) {
			mEditText.setText(result);
		}
		rightBtn = getRightTextButton();
		rightBtn.setText(getResources().getString(R.string.save));
		rightBtn.setOnClickListener(this);
		Utils.ContentLengthLimit(this,mEditText,MAX_COUNT);
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.back_button:
			this.finish();
			break;
		case R.id.right_button:	//保存
			if(TextUtils.isEmpty(mEditText.getText().toString().trim())){
				Notification.toast(this, "简介内容不能为空");
				return;
			}
			Intent intent = getIntent();
			// 把返回数据存入Intent
			intent.putExtra(Const.INTENT_SIGNATE, mEditText.getText().toString().trim());
			// 设置返回数据
			setResult(RESULT_OK, intent);
			this.finish();
			break;
		default:
			break;
		}

	}
	public void onResume() {
		super.onResume();
		MobclickAgent.onResume(this);
	}

	public void onPause() {
		super.onPause();
		MobclickAgent.onPause(this);
	}
}
